import akshare as ak
import pandas as pd

def test_delisted_stock_apis():
    """测试各退市股票API"""
    print("="*50)
    print("开始测试退市股票API")
    print("="*50)
    
    # 测试东方财富退市股票接口
    try:
        print("\n测试 ak.stock_zh_a_delist (东方财富)...")
        df_em = ak.stock_zh_a_delist()
        if not df_em.empty:
            print(f"返回列名: {df_em.columns.tolist()}")
            print(f"样本数据:\n{df_em.head(3)}")
            print(f"共获取 {len(df_em)} 条记录")
        else:
            print("返回空DataFrame")
    except Exception as e:
        print(f"东方财富接口异常: {str(e)}")
    
    # 测试上交所退市股票接口
    try:
        print("\n测试 ak.stock_info_sh_delist (上交所)...")
        df_sh = ak.stock_info_sh_delist()
        if not df_sh.empty:
            print(f"返回列名: {df_sh.columns.tolist()}")
            print(f"样本数据:\n{df_sh.head(3)}")
            print(f"共获取 {len(df_sh)} 条记录")
        else:
            print("返回空DataFrame")
    except Exception as e:
        print(f"上交所接口异常: {str(e)}")
    
    # 测试深交所退市股票接口
    try:
        print("\n测试 ak.stock_info_sz_delist (深交所)...")
        df_sz = ak.stock_info_sz_delist()
        if not df_sz.empty:
            print(f"返回列名: {df_sz.columns.tolist()}")
            print(f"样本数据:\n{df_sz.head(3)}")
            print(f"共获取 {len(df_sz)} 条记录")
        else:
            print("返回空DataFrame")
    except Exception as e:
        print(f"深交所接口异常: {str(e)}")

if __name__ == "__main__":
    test_delisted_stock_apis()
    print("\n测试完成")